package org.loofer.ext.utils;

import android.util.Pair;

public final class ArrayUtils {
    public static int getArrayDimension(Object objects) {
        int dim = 0;
        int i = 0;
        while (i < objects.toString().length() && objects.toString().charAt(i) == '[') {
            dim++;
            i++;
        }
        return dim;
    }

    public static Pair<Pair<Integer, Integer>, String> arrayToObject(Object object) {
        int cross;
        int vertical;
        int i = 0;
        StringBuilder builder = new StringBuilder();
        int length;
        if (object instanceof int[][]) {
            int[][] ints = (int[][]) object;
            cross = ints.length;
            vertical = cross == 0 ? 0 : ints[0].length;
            length = ints.length;
            while (i < length) {
                builder.append(arrayToString(ints[i]).second + "\n");
                i++;
            }
        } else if (object instanceof byte[][]) {
            byte[][] ints2 = (byte[][]) object;
            cross = ints2.length;
            vertical = cross == 0 ? 0 : ints2[0].length;
            length = ints2.length;
            while (i < length) {
                builder.append(arrayToString(ints2[i]).second + "\n");
                i++;
            }
        } else if (object instanceof short[][]) {
            short[][] ints3 = (short[][]) object;
            cross = ints3.length;
            vertical = cross == 0 ? 0 : ints3[0].length;
            length = ints3.length;
            while (i < length) {
                builder.append(arrayToString(ints3[i]).second + "\n");
                i++;
            }
        } else if (object instanceof long[][]) {
            long[][] ints4 = (long[][]) object;
            cross = ints4.length;
            vertical = cross == 0 ? 0 : ints4[0].length;
            length = ints4.length;
            while (i < length) {
                builder.append(arrayToString(ints4[i]).second + "\n");
                i++;
            }
        } else if (object instanceof float[][]) {
            float[][] ints5 = (float[][]) object;
            cross = ints5.length;
            vertical = cross == 0 ? 0 : ints5[0].length;
            length = ints5.length;
            while (i < length) {
                builder.append(arrayToString(ints5[i]).second + "\n");
                i++;
            }
        } else if (object instanceof double[][]) {
            double[][] ints6 = (double[][]) object;
            cross = ints6.length;
            vertical = cross == 0 ? 0 : ints6[0].length;
            length = ints6.length;
            while (i < length) {
                builder.append(arrayToString(ints6[i]).second + "\n");
                i++;
            }
        } else if (object instanceof boolean[][]) {
            boolean[][] ints7 = (boolean[][]) object;
            cross = ints7.length;
            vertical = cross == 0 ? 0 : ints7[0].length;
            length = ints7.length;
            while (i < length) {
                builder.append(arrayToString(ints7[i]).second + "\n");
                i++;
            }
        } else if (object instanceof char[][]) {
            char[][] ints8 = (char[][]) object;
            cross = ints8.length;
            vertical = cross == 0 ? 0 : ints8[0].length;
            length = ints8.length;
            while (i < length) {
                builder.append(arrayToString(ints8[i]).second + "\n");
                i++;
            }
        } else {
            Object[][] objects = (Object[][]) object;
            cross = objects.length;
            vertical = cross == 0 ? 0 : objects[0].length;
            length = objects.length;
            while (i < length) {
                builder.append(arrayToString(objects[i]).second + "\n");
                i++;
            }
        }
        return Pair.create(Pair.create(Integer.valueOf(cross), Integer.valueOf(vertical)), builder.toString());
    }

    public static Pair arrayToString(Object object) {
        int length;
        StringBuilder builder = new StringBuilder("[");
        if (object instanceof int[]) {
            int[] ints = (int[]) object;
            length = ints.length;
            for (int i : ints) {
                builder.append(i + ",\t");
            }
        } else if (object instanceof byte[]) {
            byte[] bytes = (byte[]) object;
            length = bytes.length;
            for (byte item : bytes) {
                builder.append(item + ",\t");
            }
        } else if (object instanceof short[]) {
            short[] shorts = (short[]) object;
            length = shorts.length;
            for (short item2 : shorts) {
                builder.append(item2 + ",\t");
            }
        } else if (object instanceof long[]) {
            long[] longs = (long[]) object;
            length = longs.length;
            for (long item3 : longs) {
                builder.append(item3 + ",\t");
            }
        } else if (object instanceof float[]) {
            float[] floats = (float[]) object;
            length = floats.length;
            for (float item4 : floats) {
                builder.append(item4 + ",\t");
            }
        } else if (object instanceof double[]) {
            double[] doubles = (double[]) object;
            length = doubles.length;
            for (double item5 : doubles) {
                builder.append(item5 + ",\t");
            }
        } else if (object instanceof boolean[]) {
            boolean[] booleans = (boolean[]) object;
            length = booleans.length;
            for (boolean item6 : booleans) {
                builder.append(item6 + ",\t");
            }
        } else if (object instanceof char[]) {
            char[] chars = (char[]) object;
            length = chars.length;
            for (char item7 : chars) {
                builder.append(item7 + ",\t");
            }
        } else {
            Object[] objects = (Object[]) object;
            length = objects.length;
            for (Object item8 : objects) {
                builder.append(ObjectUtils.objectToString(item8) + ",\t");
            }
        }
        return Pair.create(Integer.valueOf(length), builder.replace(builder.length() - 2, builder.length(), "]").toString());
    }

    public static <T> T[] toArray(T... array) {
        return (array == null || array.length == 0) ? null : array;
    }
}
